package com.qymerge.manage.base.service.impl;

import com.qymerge.manage.base.dao.IMetaCompanyDao;
import com.qymerge.manage.base.dao.IMetaCostCenterDao;
import com.qymerge.manage.base.dao.IMetaOrgDao;
import com.qymerge.manage.base.dao.IMetaOrgFeeCompanyCostCenterDao;
import com.qymerge.manage.base.ro.MetaOrgFeeCompanyCostCenterRO;
import com.qymerge.manage.base.service.IMetaOrgFeeCompanyCostCenterService;
import com.qymerge.manage.core.bean.ActionResultRO;
import com.qymerge.manage.core.bean.DataTableRO;
import com.qymerge.manage.core.bean.PageRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>Title: MetaOrgFeeCompanyCostCenterServiceImpl</p>
 * <p>Description: 费用的来源公司和成本中心</p>
 *
 * @author Xiao
 * @date 2025/4/29 18:43
 * @version 1.0.0
 */
@Service
public class MetaOrgFeeCompanyCostCenterServiceImpl implements IMetaOrgFeeCompanyCostCenterService {

    @Autowired
    private IMetaOrgFeeCompanyCostCenterDao metaOrgFeeCompanyCostCenterDao;

    @Autowired
    private IMetaOrgDao metaOrgDao;

    @Autowired
    private IMetaCompanyDao metaCompanyDao;

    @Autowired
    private IMetaCostCenterDao metaCostCenterDao;

    /**
     * 查询
     *
     * @param ro
     * @param pageRequest
     * @return
     */
    @Override
    public DataTableRO list(MetaOrgFeeCompanyCostCenterRO ro, PageRequest pageRequest) {
        List<MetaOrgFeeCompanyCostCenterRO> list = metaOrgFeeCompanyCostCenterDao.list(ro, pageRequest);
        DataTableRO dataTableRO = new DataTableRO();
        int allCount = metaOrgFeeCompanyCostCenterDao.total(ro);
        int pageSize = pageRequest.getSize();
        dataTableRO.setAll_count(allCount);
        dataTableRO.setList(list);
        dataTableRO.setCurrent_page(pageRequest.getPage());
        dataTableRO.setPage_size(pageSize);
        int allPage = (allCount % pageSize == 0 ? allCount / pageSize : allCount / pageSize + 1);
        dataTableRO.setAll_page(allPage);
        return dataTableRO;
    }

    /**
     * 详情
     *
     * @param Id
     * @return
     */
    @Override
    public MetaOrgFeeCompanyCostCenterRO detail(Long Id) {
        MetaOrgFeeCompanyCostCenterRO metaOrgFeeCompanyCostCenterDaoOne = metaOrgFeeCompanyCostCenterDao.findOne(Id);
        return metaOrgFeeCompanyCostCenterDaoOne;
    }

    @Override
    public ActionResultRO save(MetaOrgFeeCompanyCostCenterRO ro) {
        int rn = metaOrgFeeCompanyCostCenterDao.insert(ro);
        return new ActionResultRO(rn, ro.getId() == 0 ? "保存成功" : "保存失败");
    }

    @Override
    public ActionResultRO delete(Long[] ids) {
        int rn = metaOrgFeeCompanyCostCenterDao.remove(Arrays.asList(ids));
        return new ActionResultRO(true, "删除" + rn +"成功", "删除" + rn +"失败");
    }


}
